<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
        $model = $this->getModel();
        $aut = new bgAuthorize();
       
        switch(JRequest::getVar('task')){
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                JToolBarHelper::title( 'アンケート情報作成', 'info.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
                JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('edit');
                
                break;
            /* edit questionare */
            case 'edit':
                $cid = JRequest::getVar('cid');
                $this->row = $model->load($cid[0]);
            
                JToolBarHelper::title( 'アンケート編集', 'info.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('edit');
                
                break;
                
            /* add questionare */  
            case 'add':
                
            	JToolBarHelper::title( 'アンケート作成', 'info.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('add');
                
            	break;
            
            /* summary questionare */
            case 'summary':
            
                $cid = JRequest::getVar('cid');
                $this->row = $model->load($cid);
                $this->ques = $model->getQuestion($cid);
                /* count anwser */
                $this->contAns = 0;
                /* count question */
                $this->countQues = 0;
                
                JToolBarHelper::title(' アンケート:'.$this->row->SERQ_TITLE.'', 'info.png' );
                JToolBarHelper::custom('export_csv','csv.png','アンケート結果CSV出力', 'アンケート結果CSV出力',false);
                JToolBarHelper::cancel('cancel', 'キャンセル');  
                $this->setLayout('summary');
                
                break;
                
            /* csv export */    
            case 'csv':
                if($aut->getUserGroup() == '8' || $aut->getUserGroup() == '9'){
                    $cid = JRequest::getVar('cid');
                    JToolBarHelper::title('アンケート結果のダウンロード','info.png');
                    JToolBarHelper::cancel('cancel', 'キャンセル');
                    $this->setLayout('csv');
                }
            	break;
            
            /* copy questionare */    
            /*case 'copy':
                $cid = JRequest::getVar('cid');
                $this->row = $model->load($cid[0]);
                
                JToolBarHelper::title( 'アンケート情報作成', 'info.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('copy');
                
            	break;*/
            case 'popup':
                $usertype = $model->getAllUsertype();
                $mailgroup = $model->getAllMailGroup();
                $area = $model->getAllArea();
                $area_code = 0;
                $pref = $model->getAllPrefOfArea($area_code);
                
                $this->assignRef('usertype',$usertype);
                $this->assignRef('mailgroup',$mailgroup);
                $this->assignRef('area',$area);
                $this->assignRef('pref',$pref);
                
                $this->setLayout('popup');
                break;	    
                  
            /* default value */	    
            default :
                $this->list['filter_search'] = &JRequest::getVar('filter_search');
                $this->list['status'] = &JRequest::getVar('status');
                $this->rows =& $model->getAll($this->list); 
                $this->pagination =& $this->get('Pagination');
                
            	JToolBarHelper::title( 'アンケート管理', 'info.png' );
                JToolBarHelper::custom('copy','save-copy.png','コピー', 'コピー',true); 
                //JToolBarHelper::save2copy('copy','コピー');
                if($aut->checkAdd()){
                    JToolBarHelper::addNew('add','作成');
                }
                if($aut->checkEdit()){
                    JToolBarHelper::editList('edit', '編集');
                }
                if($aut->checkDelete()){
   	                JToolBarHelper::deleteList('', 'remove','削除');
                }
		}    
		parent::display();
	}
    function getList($usertype_search,$mailgroup_search,$area_search,$pref_search,$ocba_name){
        $mainframe = JFactory::getApplication();      
        $filter['ocba_name'] = $ocba_name;
        $filter['usertype_search'] = $usertype_search;
        $filter['mailgroup_search'] = $mailgroup_search;
        $filter['area_search'] = $area_search;
        $filter['pref_search'] = $pref_search;
        $model = $this->getModel();
        $lstuser = $model->getAllUserMail($filter);
        $this->rows = $lstuser;        
        return $lstuser;
    }
}




